﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Formula.aspx.cs" Inherits="Credit_Teacher_RuleSettings_Formula" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>公式设置</title>
    <link href="../../../Common/css/main.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript" src="../../../Common/Js/jquery.js"></script>

    <script type="text/javascript" src="../../../Common/Js/common.js"></script>

    <script type="text/javascript" src="../../../Common/Js/msg.js"></script>
    <script type="text/javascript">
    var current = 0;
    function OnInputIn(index)
    {
        var temp = document.getElementById("text"+index);
        modi(temp);
        if(current!=0)
        {
             document.getElementById("span"+current).style.color="Black";
        }
        current = index;
        
        document.getElementById("span"+index).style.color="Red";
        
    }
    function  OnInputOut(index)
    {
        var obj = document.getElementById("text"+index);
        var value = obj.value;
        
        if(value.length == 0 ||  ( /\D/.test(value)))
        {   
            obj.setAttribute("value",obj.getAttribute("oldvalue")); 
        }
        else
        {
            obj.setAttribute("oldvalue",value); 
        }
        unModi(obj,'right');
        
        document.getElementById("span"+index).style.color="Black";
        current=0;
    }
        //编辑状态
    function modi(obj)
    { 
        obj.style.textAlign = 'left';  
 
        obj.select();


    }
        //非编辑状态
    function unModi(obj,align)
    {
       obj.style.textAlign = align;  

    }
    function OnInputKeyPress()
    {
        return event.keyCode>=48&&event.keyCode<=57;
    }
    
    function ReSet() {
        PageMethods.GetParams(Number($("#hidCourseID").val()), 
        function(result){
            var tempO;
            for (var i = 0; i < result.length; i++) { 
                tempO = document.getElementById("text"+(i+1));
                tempO.value = result[i].Paramer ;
                tempO.oldvalue = result[i].Paramer ;
                tempO.KeyWord = result[i].KeyWord ;
            }
        },
        function(err){showMassgeBox("提示",err._message,1,null);});
    }
    
    function SaveSet() {
        var param = new Array();
        var keywords = new Array();
        for(var i = 1;i<6;i++) {
            param[i-1]=parseInt( document.getElementById("text"+i).value);
            keywords[i-1] = document.getElementById("text"+i).KeyWord;
        }
        PageMethods.SaveParamSet(Number($("#hidCourseID").val()), param, keywords, 
        function(result){
            showMassgeBox("提示","保存成功",1,null);
        },function(err){showMassgeBox("提示",err._message,1,null);});
    }
    
    
    </script>
</head>
<body>
<body style="padding-top:5px;">
<form id="form1" runat="server">
<div class="mainWarp">
    <div class="pageBody">
     <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True">
     </asp:ScriptManager>
        <div style="float: left; height: 98%; width: 150px;">
            <div class="menuBody">
                <div class="menuList">
                    <dl>
                        <ul id="courseList">
                        </ul>
                    </dl>
                </div>
            </div>
        </div>
        <div style="height: 200px;" style="float: left; height: 98%;">
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
            <input type="button" class="commonBut" id="btnAddKind" value="保存" onclick="SaveSet()" />
            <input type="reset" class="commonBut" id="btnSaveKind" value="重置" onclick="ReSet()" />
            <table id="settingTable" border="0" cellpadding="0" cellspacing="1" style="width: 50%;"
                class="useList">
                <tr>
                    <th width="100%" style="text-align: left; padding-left: 5px;">
                        公式解释:</th>
                </tr>
                <tr>
                    <td width="100%" style="text-align: left; padding-left: 5px;">
                        <span id="courseName1"></span>学期学分=<br>
                        （<span id="span1" style="color: Black">基本分</span>+<span id="span2" style="color: Black">平时表现分</span>×平时各项加减累计分数/<span
                            id="span3" style="color: Black">封顶分</span>）×<span id="span4" style="color: Black">平时表现权重</span>%
                        + 期末成绩×<span id="span5" style="color: Black">期末成绩权重</span>%</td>
                </tr>
            </table>
            <table id="Table1" border="0" cellpadding="0" cellspacing="1" style="width: 50%;"
                class="useList">
                <tr>
                    <th width="100%" style="text-align: left; padding-left: 5px;">
                        最终公式:</th>
                </tr>
                <tr>
                    <td width="100%" style="text-align: left; padding-left: 5px;">
                        <span id="courseName2"></span>学期学分=<br>
                        （<input id="text1" onkeypress="return OnInputKeyPress();" onpaste="return false;"
                            ondragenter="return false" maxlength="4" onclick="OnInputIn(1)" onfocusout="OnInputOut(1)"
                            type="text" value="60" oldvalue="60" style="width: 30px; text-align: right;" />+
                        <input id="text2" onkeypress="return OnInputKeyPress();" onclick="OnInputIn(2)" onpaste="return false;"
                            ondragenter="return false" maxlength="4" onfocusout="OnInputOut(2)" type="text"
                            value="40" oldvalue="40" style="width: 30px; text-align: right;" />×平时各项加减累计分数/
                        <input id="text3" onkeypress="return OnInputKeyPress();" onclick="OnInputIn(3)" onpaste="return false;"
                            ondragenter="return false" maxlength="4" onfocusout="OnInputOut(3)" type="text"
                            value="200" oldvalue="200" style="width: 30px; text-align: right;" />）×
                        <input id="text4" onkeypress="return OnInputKeyPress();" onclick="OnInputIn(4)" onpaste="return false;"
                            ondragenter="return false" maxlength="4" onfocusout="OnInputOut(4)" type="text"
                            value="70" oldvalue="70" style="width: 30px; text-align: right;" />% + 期末成绩×
                        <input id="text5" onkeypress="return OnInputKeyPress();" onclick="OnInputIn(5)" onpaste="return false;"
                            ondragenter="return false" maxlength="4" onfocusout="OnInputOut(5)" type="text"
                            value="30" oldvalue="30" style="width: 30px; text-align: right;" />%</td>
                </tr>
            </table>
            <input type="hidden" id="hidCourseID" />
            </ContentTemplate>
            </asp:UpdatePanel>
        </div>

    </div>
</div>
    </form>
</body>
</body>
</html>
<script language="javascript">
<% InitKeyParam(); %>
$(document).ready(FormulaReadyFunc);
function FormulaReadyFunc(){
    PageMethods.GetCourse(
        function(result){
            InitCourseList(result);
        },
        function(err){
            showMassgeBox("提示",err._message,1,null);
        });
}

function InitCourseList(courseList){
    if(courseList == null || courseList.length < 1)
        return;
    var courseHtml = "";
    for(var i = 0 ; i < courseList.length; i++){
        courseHtml += "<li name='"+courseList[i].RID+"'><a href='#' onClick='ShowCourseFormula("+courseList[i].RID+");'>"+courseList[i].CauseName+"</a></li>";
    }
    $("#courseList").html(courseHtml);
}

function ShowCourseFormula(courseID){
    $("#courseList").children().each(
        function(){
            if($(this).attr("name") == courseID){
                $(this).toggleClass("active");
                var s = $(this).find("a").text();
                $("#courseName1").text(s);
                $("#courseName2").text(s);
            }
            else
                $(this).removeClass("active");
        }
    );
    
    PageMethods.GetCipher(Number(courseID), 
        function (succ){
            $("#hidCourseID").val(courseID);
            for(var i = 0; i < succ.length; i++){
                switch(succ[i].KeyWord){
                    case "BaseScore":
                        $("#text1").attr("oldvalue", succ[i].Paramer);
                        $("#text1").val(succ[i].Paramer);
                        break;
                    case "ExpressScore":
                        $("#text2").attr("oldvalue", succ[i].Paramer);
                        $("#text2").val(succ[i].Paramer);
                        break;
                    case "MaxExpressScore":
                        $("#text3").attr("oldvalue", succ[i].Paramer);
                        $("#text3").val(succ[i].Paramer);
                        break;
                    case "ExpressWeight":
                        $("#text4").attr("oldvalue", succ[i].Paramer);
                        $("#text4").val(succ[i].Paramer);
                        break;
                    case "TermEndWeight":
                        $("#text5").attr("oldvalue", succ[i].Paramer);
                        $("#text5").val(succ[i].Paramer);
                        break;
                }}
        });
}

</script>